package concept.misc;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Currency;
import java.util.Formatter;
import java.util.Locale;

public class FormatterLab
{
	static void doPrintf()
	{
		System.out.printf("45%2$b%3$+04d\n", 978,654,321,111); 
	}
	
	static void doNumberFormat()
	{
		Double amount = 123456.789;
		NumberFormat numberFormatter = NumberFormat.getNumberInstance(Locale.GERMAN);
		String amountOut = numberFormatter.format(amount);
		System.out.printf("amountOut=%s, amount.toString()=%s\n", amountOut, amount.toString());
	}
	
	static void doCurrencyFormat()
	{
		double currency = 123456.789;
		Locale locale = Locale.UK;
		NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
		String currencyOut = currencyFormatter.format(currency);
		System.out.printf("currencyOut=%2$s, Locale=%1$s\n", locale, currencyOut);
		try
		{
			Number money = currencyFormatter.parse("£45,000.12");
			System.out.printf("money=%1$.2f\n", money);
		}
		catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	static void doPercentFormat()
	{
		double percent = .75;
		NumberFormat percentFormatter = NumberFormat.getPercentInstance();
		System.out.println(percentFormatter.format(percent));
	}
	
	static void doCurrency()
	{
		Currency currency = NumberFormat.getCurrencyInstance(Locale.CANADA).getCurrency();
		System.out.println(currency.getCurrencyCode());
	}
	
	static void doFormatter()
	{
		Formatter formatter = new Formatter(new StringBuilder("Who follows me? "), Locale.UK); 
		formatter.format("%s follow(s) me. ", "You");
		System.out.println(formatter.toString());
	}
	
	static void doString()
	{
		String s = "Heal the world, make it better place, for you and for me, and the entire of human race.";
		String ss[] =s.split(",");
		for(String i:ss)
		{
			System.out.print(i+"-");
		}
		ss = s.split(",", 5);
		System.out.println("\n*********");
		for(String i:ss)
		{
			System.out.print(i+"-");
		}
	}
	public static void main(String[] args)
	{
		//doPrintf();
		//doFormatter();
		//doString();
		//doNumberFormat();
		doCurrencyFormat();
		//doPercentFormat();
	}
}
